Ext.namespace('Maint.List');

Maint.List.panel = function(){
	// **工单类型下拉列表值
	this.selectItems = new Ext.data.SimpleStore({
        fields: ['value', 'text'],
        data: [ [61,'基站故障工单'],
				[62,'传输故障工单'],
				[63,'质量故障工单'],
				[64,'客服工单'],
				[65,'跟踪工单'],
				[66,'任务工单'],
				[67,'性能故障小区工单'],
				[68,'集团业务投诉故障工单'],
				[69,'基站入网工单']]
    });
    
    // 工单区间开始时间
    this.txtStartDate = new Ext.form.DateField({
    	fieldLabel: '开始日期',
		emptyText: '请选择',
		format:'Y-m-d',
		disabledDays:[0-6],
		width: 122
    });
    
    // 工单区间结束时间
    this.txtEndDate = new Ext.form.DateField({
    	fieldLabel: '结束日期',
		emptyText: '请选择',
		format:'Y-m-d',
		disabledDays:[0-6],
		width: 122
    });
    
    // 下拉列表框
    this.maintType = new Ext.form.ComboBox({
    	xtype: 'combo',
    	fieldLabel: '工单类型',
    	store: this.selectItems, 
    	triggerAction: 'all',
		value: 61,
		valueField: 'value',
		displayField: 'text',
		mode: 'local',
		width: 122
    });
    
    // 工单流水号
    this.txtWoNum = new Ext.form.TextField({fieldLabel: '工单流水号' });
    
    // 工单查询的面板
    this.searchForm = new Ext.form.FormPanel({
        labelAlign: 'right',
        labelWidth: 120,
        labelHight: 60,
        height:130,
        region: 'north',
        title: '工单查询',
        frame:true,
        items: [{
            layout:'column',
            items: [{
                columnWidth:.48,
                layout : 'form',
                items:[this.maintType, this.txtStartDate ]
            },{
                columnWidth:.52,
                layout : 'form',
                items:[this.txtWoNum, this.txtEndDate ]
            }]
        }],
        buttons: [{
            text: '更新',
            handler: this.refreshMaint,
            scope: this
        },{
            text: '查找',
            handler: this.showMaintBy,
            scope: this
        },{
        	text: '上报',
            handler: this.toReport,
            scope: this
        }]
    });
      
    // **grid的列
	this.cm = new Ext.grid.ColumnModel([
		{header:'工单类型',dataIndex:'TYPE_TITLE', width:100},
		{header:'工单流水号',dataIndex:'WO_NUM', width:150},
		{header:'工单主题',dataIndex:'TOPIC', width:150},
		{header:'派单部门',dataIndex:'CREATE_DEP', width:80},
		{header:'派单人',dataIndex:'CREATE_BY', width:80},
		{header:'派单时间',dataIndex:'CREATE_TIME', width:90},
		{header:'联系方式',dataIndex:'CONTACT', width:85}
	]);
	
	this.store = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
			url: '../supervise/searchMaintByType.form',
			method: 'POST'
		}),
		reader: new Ext.data.JsonReader({
			root: 'result',
			totalProperty: 'total',
			id: 'MAINT_ID',
			fields: ['MAINT_ID', 'TYPE', 'TYPE_TITLE', 'WO_NUM', 'TOPIC', 'CREATE_DEP', 'CREATE_BY', 'CREATE_TIME', 'CONTACT']
		}),
		listeners:{
			 beforeload :{    
	    	  	fn : function(thiz,options){
       	          	Ext.apply(thiz.baseParams,{ 
					maintType: this.maintType.getValue(),			
			  		txtStartDate:this.txtStartDate.getRawValue(),
			   		txtEndDate:this.txtStartDate.value
       	          });    
              },
              scope:this 
	    	}
		}
		
	});

    // grid
	this.grid = new Ext.grid.GridPanel({
		store: this.store,
		region:'center',
		cm: this.cm,
		sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
		bbar: new Ext.PagingToolbar({
			pageSize: 15,
			store: this.store,
			displayInfo: true,
            displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
            emptyMsg: "没有记录"
		}),
		listeners:{
			// 双击事件
			rowdblclick : function(grid ,rowIndex ,e){
				var data = grid.store.getAt(rowIndex).data;	//json
				Ext.Ajax.request({
					url: '../supervise/searchById.form',
					method: 'POST',
					params: {
						maintId: data.MAINT_ID,
						maintType: data.TYPE
					},
					success:function(rsp){
						var data = Ext.util.JSON.decode(rsp.responseText).result;
						//	this.text_field.setValue(data.name);
						if (data.TYPE == '61'){
							if(!Maint.Show61.showInfo.instance)
								Maint.Show61.showInfo.instance = new Maint.Show61.showInfo();
							Maint.Show61.showInfo.instance.show();
							Maint.Show61.showInfo.instance.initDetail(data);
						} else if (data.TYPE == '62'){
							if(!Maint.Show62.showInfo.instance)
								Maint.Show62.showInfo.instance = new Maint.Show62.showInfo();
							Maint.Show62.showInfo.instance.show();
							Maint.Show62.showInfo.instance.initDetail(data);
						} else if (data.TYPE == '63'){
							if(!Maint.Show63.showInfo.instance)
								Maint.Show63.showInfo.instance = new Maint.Show63.showInfo();
							Maint.Show63.showInfo.instance.show();
							Maint.Show63.showInfo.instance.initDetail(data);
						} else if (data.TYPE == '64'){
							var customerInfo = Ext.util.JSON.decode(rsp.responseText).customerInfo;
							if(!Maint.Show64.showInfo.instance)
								Maint.Show64.showInfo.instance = new Maint.Show64.showInfo();
							Maint.Show64.showInfo.instance.show();
							Maint.Show64.showInfo.instance.initDetail(data);
							Maint.Show64.showInfo.instance.initCustomerInfo(customerInfo);
						} else if (data.TYPE == '65'){
							if(!Maint.Show65.showInfo.instance)
								Maint.Show65.showInfo.instance = new Maint.Show65.showInfo();
							Maint.Show65.showInfo.instance.show();
							Maint.Show65.showInfo.instance.initDetail(data);
						} else if (data.TYPE == '66'){
							if(!Maint.Show66.showInfo.instance)
								Maint.Show66.showInfo.instance = new Maint.Show66.showInfo();
							Maint.Show66.showInfo.instance.show();
							Maint.Show66.showInfo.instance.initDetail(data);
						} else if (data.TYPE == '67'){
							if(!Maint.Show67.showInfo.instance)
								Maint.Show67.showInfo.instance = new Maint.Show67.showInfo();
							Maint.Show67.showInfo.instance.show();
							Maint.Show67.showInfo.instance.initDetail(data);						
						} else if (data.TYPE == '68'){
							if(!Maint.Show68.showInfo.instance)
								Maint.Show68.showInfo.instance = new Maint.Show68.showInfo();
							Maint.Show68.showInfo.instance.show();
							Maint.Show68.showInfo.instance.initDetail(data);
						} else if (data.TYPE == '69'){
							if(!Maint.Show69.showInfo.instance)
								Maint.Show69.showInfo.instance = new Maint.Show69.showInfo();
							Maint.Show69.showInfo.instance.show();
							Maint.Show69.showInfo.instance.initDetail(data);
						}
					},
					failure:function(){}
				});
			}
		}	
	});
	
	// 构造函数
	Maint.List.panel.superclass.constructor.call(this, {
		region:'center',
		layout:'border',
		items:[this.searchForm, this.grid ],
		listeners:{
			render:this.showMaintBy
		}
	});
};

Ext.extend(Maint.List.panel, Ext.Panel, {
	showMaintBy: function() {
		this.store.load({
			params:{
				start: 0,
				limit: 15,
				maintType: this.maintType.getValue(),
			    txtStartDate: this.txtStartDate.getRawValue(),
			   	txtEndDate: this.txtEndDate.getRawValue(),
			    txtWoNum: this.txtWoNum.getValue()
			}
		})
	},
	
	toReport: function() {
		var record = this.grid.getSelectionModel().getSelected();
		if (null == record) {
			Utils.warn('请选择一条数据!');
			return ;
		} 
				Ext.Ajax.request({
					url: '../supervise/checkMaintIsReport.form',
					method: 'POST',
					params: {
						maintId: record.data.MAINT_ID,
						maintType: record.data.TYPE
					},
					success:function(rsp){
						var data = Ext.util.JSON.decode(rsp.responseText).result;
						if (data !=null && data !=''){
							Utils.warn('该信息已上报!');
							return;
						}else {
							Maint.toReport.win.instance = new Maint.toReport.win();
							Maint.toReport.win.instance.show();
							Maint.toReport.win.instance.initAdd(record.data);
						}
						
					},
					failure:function(){ Util.info('文件更新失败!');}
				});
	},
	
	refreshMaint: function() {
		Ext.Ajax.request({
					url: '../supervise/checkFileByFolder.form',
					method: 'POST',
					params: {},
					scope: this,
					success:function(rsp){
						var data = Ext.util.JSON.decode(rsp.responseText).result;
						Ext.MessageBox.alert('提示', data, this.aaa);
					},
					failure:function(){
					}
				});
	},
	
	aaa: function(){}
	
});